package fr.neyb.wesb.core.job.jobs;

import java.util.Arrays;
import java.util.List;

import fr.neyb.wesb.core.data.content.Record;
import fr.neyb.wesb.core.data.descriptors.record.RecordDescriptor;
import fr.neyb.wesb.core.data.io.RecordReader;
import fr.neyb.wesb.core.data.io.RecordWriter;
import fr.neyb.wesb.core.job.impl.UnitJob;

/**
 * a job that just copy a source to an other.
 * 
 * @author adeconin
 * 
 */
public class CopyJob extends UnitJob {

	public CopyJob(RecordDescriptor inputsDescriptor) {
		super(Arrays.asList(new RecordDescriptor[] { inputsDescriptor }),
				Arrays.asList(new RecordDescriptor[] { inputsDescriptor }));
	}

	@Override
	protected void doJob(List<RecordReader> readers, List<RecordWriter> writers) {
		RecordReader r = readers.get(0);
		RecordWriter w = writers.get(0);

		Record rec;
		while ((rec = r.read()) != null) {
			w.write(rec);
		}
	}

}
